import { request } from '@/utils/request/axios';
import { ErrorMessageMode, PageRequest, PageData } from '#/request';
import { MenuInfoOutputDtos, MenuInfoOutputDto, MenuInfoInputDto } from './model/menuModel';

/** 菜单模块URL枚举 */
enum Api {
  /** 获取菜单 */
  GetMenus = '/api/menu/getMenus',
  /** 读取菜单 */
  ReadMenus = '/api/admin/menu/read',
  /** 新增菜单 */
  CreateMenus = '/api/admin/menu/create',
  /** 更新菜单 */
  UpdateMenus = '/api/admin/menu/update',
  /** 删除菜单 */
  DeleteMenus = '/api/admin/menu/delete',
}

/**
 * 获取菜单
 * @param mode 错误消息模型
 */
export function getMenus(mode: ErrorMessageMode = 'message') {
  return request.get<MenuInfoOutputDtos>(
    {
      url: Api.GetMenus,
    },
    {
      errorMessageMode: mode,
    },
  );
}

/**
 * 读取菜单
 * @param params 分页请求
 * @param mode 错误消息模型
 */
export function readMenus(params: PageRequest, mode: ErrorMessageMode = 'message') {
  return request.post<PageData<MenuInfoOutputDto>>(
    {
      url: Api.ReadMenus,
      params: params,
    },
    {
      errorMessageMode: mode,
    },
  );
}

/**
 * 新增菜单
 * @param dtos DTO信息
 * @param mode 错误消息模型
 */
export function createMenus(dtos: MenuInfoInputDto[], mode: ErrorMessageMode = 'message') {
  return request.post(
    {
      url: Api.CreateMenus,
      params: dtos,
    },
    {
      errorMessageMode: mode,
    },
  );
}

/**
 * 菜单信息
 * @param dtos DTO信息
 * @param mode 错误消息模型
 */
export function updateMenus(dtos: MenuInfoInputDto[], mode: ErrorMessageMode = 'message') {
  return request.post(
    {
      url: Api.UpdateMenus,
      params: dtos,
    },
    {
      errorMessageMode: mode,
    },
  );
}

/**
 * 删除菜单
 * @param ids 要删除的编号集合
 * @param mode 错误消息模型
 */
export function deleteMenus(ids: (string | bigint)[], mode: ErrorMessageMode = 'message') {
  return request.post(
    {
      url: Api.DeleteMenus,
      params: ids,
    },
    {
      errorMessageMode: mode,
    },
  );
}
